module.exports = function ($) {

	var dlq = angular.element(document).ready(function () {


		//angular.bootstrap(document, ['app']);

		//return ;

		//获取用户信息
		$.ajax({
            url : '/api/as/info',
            type : "GET",
            dataType : 'json'
        }).then(function (res1) {

        //获取用户的拥有的菜单列表
		$.ajax({
			url : '/api/as/sc/menu/userMenuList',
			type : "GET",
			dataType : 'json'
		}).then(function (res) {

			if (res.errcode === 0) {

				//按钮显示权限
				var permissions = new Array();

				angular.module('app').run(['$rootScope', '$location', 'angularPermission', function ($rootScope, $location, angularPermission) {

					$rootScope.sys_list = res.data;

					$rootScope.userPermissionList = permissions;

					angularPermission.setPermissions($rootScope.userPermissionList);
					

				}]);


				angular.module('app').config(function($provide, $qProvider, $urlRouterProvider){

					$provide.service('dlq', function(){
				        this.title = res1.company_name;
	    			})

	    			$qProvider.errorOnUnhandledRejections(false);

	    			var dashboard = '';
	    			for(var i = 0; i < res.data.length; i++){
	    				var tmp = res.data[i];

	    				if(tmp.href && tmp.href != ''){
	    					dashboard = tmp.href;
	    					break;
	    				}
	    			}

	    			if(dashboard == ''){
	    				$urlRouterProvider.otherwise('/app/supplier_dashboard');
	    			}else{
	    				$urlRouterProvider.otherwise(dashboard);
	    			}
	    			

				})

				angular.bootstrap(document, ['app']);			

			} else {

				window.location = "/login.html";

			}
			
		});

		});

		return;

	});

};